package com.njtcedu.microblog.common.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "comments" ,schema = "microblog")
public class Comments implements Serializable{

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Integer id;
	
	@Column(name = "comments_content", length = 140, nullable =false)
	private String commentsContent;//评论内容

	@ManyToOne(cascade = CascadeType.REFRESH , optional = false )
	@JoinColumn(name = "user_id", nullable = false)
	private User user;//发表评论的人
	
	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "content_id", nullable =false)
	private Content content;
	
	@Column(name = "comments_date", nullable = true)
	@Temporal(TemporalType.TIMESTAMP)
	private Date commentsDate;//评论时间
	
	@Column(name = "status", length = 2, nullable = false)
	private String status;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getCommentsContent() {
		return commentsContent;
	}

	public void setCommentsContent(String commentsContent) {
		this.commentsContent = commentsContent;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Content getContent() {
		return content;
	}

	public void setContent(Content content) {
		this.content = content;
	}

	public Date getCommentsDate() {
		return commentsDate;
	}

	public void setCommentsDate(Date commentsDate) {
		this.commentsDate = commentsDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == this) return true;
		if(obj == null || obj.getClass() != getClass()) return false;
		Comments comments = (Comments)obj;
		return id != null ? id.equals(comments.id) : comments.id == null;
	}

	@Override
	public String toString() {
		return "Comments [id=" + id + ", commentsContent=" + commentsContent
				+ ", user=" + user + ", content=" + content + ", commentsDate="
				+ commentsDate + ", status=" + status + "]";
	}
	
}
